<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('日报统计列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>工作组：</label>
                                <select name="deptId" id="deptId" class="form-control " th:with="dept=${@deptService.selectChildrenDeptById(103)}" onChange="selectDept()">
                                    <option value="">全部</option>
                                    <option th:each="d : ${dept}" th:text="${d.deptName}" th:value="${d.deptId}" ></option>
                                </select>
                            </li>
                            <li>
                                <label>用户：</label>
                                <select name="userId" id="userId" class="form-control">
                                    <option value="">全部</option>
                                </select>
                            </li>
                            <li>
                                <label>产品/项目：</label>
                                <select name="productType" id="productType" onChange="selectProduct()">
                                    <option value="">全部</option>
                                    <option value="0">产品</option>
                                    <option value="1">项目</option>
                                </select>
                            </li>
                            <li>
                                <label>产品/项目名称：</label>
                                <select name="productId" id="productId" class="form-control">
                                    <option value="">全部</option>
                                </select>
                            </li>
                            <li>
                                <label>日报日期：</label>
                                <input type="text" class="time-input" placeholder="请选择查询日报日期" name="daliyDate" id="daliyDate"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:daliy:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: datetimepicker-js" />
     <th:block th:include="include :: select2-css" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: bootstrap-table-fixed-columns-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/daliy";

        function selectDept(){
            var url;
            var deptId=$("#deptId").val();
            if ('' == deptId) {
                return;
            }
            url = "/system/user/list/"+ deptId;
            $.ajax({
                cache: true,
                type: "GET",
                url: url,
                async: false,
                success: function(result) {
                    data = result.data
                    if (result.code == web_status.SUCCESS) {
                        $('#userId').empty().append('<option value="">全部</option>');
                        for(var i in data){
                            var userId = data[i].userId;
                            var userName =data[i].userName;
                            $('#userId').append
                            ('<option value="'+userId+'">'+userName+'</option>');
                        };
                        $('#userId').selectpicker('refresh');
                        $('#userId').selectpicker('render');
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            });
        }
        function selectProduct(){
            var url;
            var productType=$("#productType").val();
            if ('' == productType) {
                return;
            }
            url = "/system/product/"+ productType;
            $.ajax({
                cache: true,
                type: "GET",
                url: url,
                async: false,
                success: function(result) {
                    data = result.data
                    if (result.code == web_status.SUCCESS) {
                        $('#productId').empty().append('<option value="">全部</option>');
                        for(var i in data){
                            var productId = data[i].productId;
                            var productName =data[i].productName;
                            $('#productId').append
                            ('<option value="'+productId+'">'+productName+'</option>');
                        };
                        $('#productId').selectpicker('refresh');
                        $('#productId').selectpicker('render');
                    } else {
                        $.modal.alertError(result.msg);
                    }
                }
            });
        }
        function initialDate(){
            var tomorrow=[[${workTomorrow}]]
            $("input[name='daliyDate']").val(tomorrow);
        }
        function footerStyle(column) {
            return {
                userBalance: {
                    css: { color: 'red', 'font-weight': 'normal' }
                }
            }[column.field]
        }
        $(function() {
            initialDate();
            var options = {
                url: prefix + "/statistics",
                exportUrl: prefix + "/export",
                modalName: "日报",
                showToggle: false,
                fixedColumns: true,
                fixedNumber: 3,
                fixedRightNumber: 1,
                showFooter: true,
                footerStyle: footerStyle,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'daliyId',
                    title: '日报id',
                    visible: false
                },
                {
                    field: 'daliyDate',
                    title: '日报日期',
                    class: 'text-nowrap',
                },
                {
                    field: 'productName',
                    title: '产品/项目名称',
                    class: 'text-nowrap',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'deptName',
                    title: '工作团队',
                    class: 'text-nowrap',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'userName',
                    title: '姓名',
                    class: 'text-nowrap',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },

                {
                    field: 'workTime',
                    title: '项目总工时',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].workTime);
                        }
                        return "项目总工时汇总：" + sumBalance;
                    }
                },
                {
                    field: 'standardLaborTime',
                    title: '标准工时差',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(row.workTime-value);
                    },
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        var sumBalance2 = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].workTime);
                            sumBalance -= parseFloat(value[i].standardLaborTime);
                        }
                        return "标准工时差汇总：" + sumBalance;
                    }
                },
                {
                    field: 'codeAmount',
                    title: '总代码量',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].codeAmount);
                        }
                        return "总代码量汇总：" + sumBalance;
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>